package com.loongson;
import java.io.IOException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;  
import java.util.concurrent.TimeUnit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class OpenstackAutoService {
	
	private static Logger logger = LoggerFactory.getLogger(OpenstackAutoService.class);
	private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
	public void vmPoolsManagement(String conf, String vmNames) {

		logger.info("Vm auto task scheduler start");
		//每天24点开始执行
		long initalDelay = UtilTool.getDelay(0, 0, 0);
		//周期为24小时
		long period = 3600 * 24;
		logger.info("Configure file:" + conf + " vmNames:" + vmNames);
		final OpenstackScheduledExecutor thread = new OpenstackScheduledExecutor(conf, vmNames);
		scheduler.scheduleAtFixedRate(thread, initalDelay, period, TimeUnit.SECONDS);

	}
	
	public static void main(String[] args) throws InterruptedException, IOException {
		logger.info("Start");
		OpenstackAutoService osAuto = new OpenstackAutoService();
		osAuto.vmPoolsManagement("publicpool.properties","vmnames.txt");
		

	}
}
